﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>游戏</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link rel="stylesheet" type="text/css" href="css/Global.css" media="all" />

	<script stype="text/javascript">
	
	   var opens = []; //存放用于抽奖的1~200
	   var dict = {4:10,3:5,2:3,1:1}; //存放抽奖规则
	   var theLno = 5; //当前第几等奖
	   // var nodes = null; //当前被抽中的
	   
	   var cNum = 0;   //递增值，摇号次数
	   var theNum = 60; //停止条件值
	   var theTimer = null;
	   
	   
	   //初始化抽奖编码
	   (function initOpens(){
	   	  for(var n = 0; n < 200; n++) {
	   	    opens[n] = n + 1;
	   	  }
 	   })(); 
	   
	   //实现抽奖
	   function doGame() {
	   	  if(theLno == 1) return;
	   	  theLno--;
	   	  $("lno").innerHTML = theLno + "等奖:";
	   	 // nodes = selectNo(); //选出中奖号码
	   	  okview(); //渲染界面
	   }

    function selectFrom(iFirstValue, iLastValue){
	    var iChoices = iLastValue-iFirstValue+1;   
	    var temp = Math.floor(Math.random()*iChoices+iFirstValue);   
	    if(temp < 10){   
	      return "00"+temp;   
	    }else if(temp < 100){   
	      return "0"+temp;   
	    }else{   
	      return temp;  
	    } 
	  }
    	   
	  function okview(){
	  	cNum++;
	  	theTimer = setTimeout("okview()", 2);
	    var nos = dict[theLno]; //获得要抽出的号码个数
	    if(nos == 3){
	      $("_c").style.paddingLeft = "180px";
	    }else if(nos == 1) {
	    	$("_c").style.paddingLeft = "360px";
	    }
	    var html = "";
	    if(cNum > theNum) {
	    	 cNum = 0;
	  		 clearTimeout(theTimer);
	  		 var nodes = selectNo(); //选出中奖号码
	  		 for(var j = 0; j < nodes.length; j++) {
	  		 	  html += "<div class=\"or\" id=\"no" + j + "\"><span>" + nodes[j] + "</span></div>";
	  		 }
	  		 $("_c").innerHTML = html;
	       return;
	   	}
	   	
	    for(var n = 0; n < nos; n++) {
	       var no = selectFrom(1, 200);
	       html += "<div class=\"or\" id=\"no" + n + "\"><span>" + no + "</span></div>";
	    }
	   	$("_c").innerHTML = html;
	  } 
	
	 
	
	  //在opens中产生随机数
	  function myRandom(){
	  	 var iChoices = opens.length;   
	     var cusor = Math.floor(Math.random()*iChoices+0);
	     var rval = opens[cusor];
	     opens.splice(cusor, 1);
	     return rval;
	  }
	  
	  function selectNo() {
	  	var nos = dict[theLno]; //获得要抽出的号码个数
	  	var rval = [];
	    for(n = 0; n < nos; n++) {
	       rval[n] = myRandom();
	    } 
	    return rval;
	  }
	  
	  function $(i) {
	     return document.getElementById(i);
	  }
	  
	  //注册事件
	  document.onkeydown = function(_e){
      	 _e = _e || event;
      	 if(_e.keyCode == 32) doGame();
    };
	</script>

</head>
<body>
<div class="abody" style="height:600px;">
<div class="logo_media"><img src="images/logo_media.png" /></div>
<div class="logo"><img src="images/logo.png" /></div>
<div class="line_01" id="lno">4等奖:</div>
<div class="line_02" id="_c">
<div class="or" id="no1"><span>000</span></div>
<div class="or" id="no2"><span>000</span></div>
<div class="or" id="no3"><span>000</span></div>
<div class="or" id="no4"><span>000</span></div>
<div class="or" id="no5"><span>000</span></div>
<div class="or" id="no1"><span>000</span></div>
<div class="or" id="no2"><span>000</span></div>
<div class="or" id="no3"><span>000</span></div>
<div class="or" id="no4"><span>000</span></div>
<div class="or" id="no5"><span>000</span></div>
</div>
</div>
</body>
</html>


